package service

import (
	"time"
	"yybk/model"
	"yybk/serializer"
)

type ResponderTeacherStop struct {
	ResponderId int32 `form:"responder_id" json:"responder_id" `
}

func (service ResponderTeacherStop) Stop() (model.Responder, *serializer.Response) {
	var responder model.Responder

	if err := model.DB.Where("id = ?", service.ResponderId).First(&responder).Error; err != nil {
		return responder, &serializer.Response{
			Status: 500,
			Data:   err,
			Msg:    "数据库查询失败",
			Error:  "DB SELECT ERROR",
		}
	}

	now := time.Now()
	responder.EndTime = &now

	if err := model.DB.Save(&responder).Error; err != nil {
		return responder, &serializer.Response{
			Status: 500,
			Data:   err,
			Msg:    "数据库插入失败",
			Error:  "DB UPDATE ERROR",
		}
	}

	return responder, nil
}
